<template>
	<el-form label-width="130px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">

				<el-form-item label="指挥装备编码" prop="code">
					<el-input v-model="form.code" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="装备名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>


				<el-form-item label="部署网络" prop="cnId">
					<el-input v-model="form.cnId" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="部署指挥场所" prop="cpId">
					<el-input v-model="form.cpId" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="部署要素房间" prop="cpeId">
					<el-input v-model="form.cpeId" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="装备类型" prop="type">
					<el-input v-model="form.type" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="关键参数" prop="key">
					<el-input v-model="form.key" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="品牌" prop="brand">
					<el-input v-model="form.brand" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="型号" prop="model">
					<el-input v-model="form.model" style="width: 190px;"></el-input>
				</el-form-item>


			</el-col>
			<el-col :span="12">

				<el-form-item label="数量" prop="serialNumber">
					<el-input v-model="form.serialNumber" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'serialNumber', 0)"></el-input>
				</el-form-item>

				<el-form-item label="设备规格" prop="specification">
					<el-input v-model="form.specification" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="产地" prop="placeOfOrigin">
					<el-input v-model="form.placeOfOrigin" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="生产厂家" prop="manufacturer">
					<el-input v-model="form.manufacturer" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="出厂日期" prop="dateOfProduction">
					<el-date-picker v-model="form.dateOfProduction" type="date" size="default" format="YYYY-MM-DD"
						value-format="YYYY-MM-DD" style="width: 190px;" />
				</el-form-item>

				<el-form-item label="启用日期" prop="commissioningDate">
					<el-date-picker v-model="form.commissioningDate" type="date" size="default" format="YYYY-MM-DD"
						value-format="YYYY-MM-DD" style="width: 190px;" />
				</el-form-item>


				<el-form-item label="报废日期" prop="dateOfRetirement">
					<el-date-picker v-model="form.dateOfRetirement" type="date" size="default" format="YYYY-MM-DD"
						value-format="YYYY-MM-DD" style="width: 190px;" />
				</el-form-item>


				<el-form-item label="设备生命周期状态" prop="lifeStatus">
					<el-input v-model="form.lifeStatus" style="width: 190px;"></el-input>
				</el-form-item>


			</el-col>
		</el-row>

		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'

	import {
		regOnlyNumSpot
	} from '@/utils/reg'

	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData'])

	const form = ref({})

	const queryForm = ref('')


	//必填项
	const rules = reactive({

		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}]


	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zhtx/equipmenta/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>